<template>
    <div>

      <el-row :gutter="1" style="border: 1px solid white">
        <el-col :span="4" :offset="8" style="">
          <el-button type="success" style="float: right"@click="addOperator2()">添加操作员</el-button>
        </el-col>
      </el-row>
      <el-dialog title="成员信息" :visible.sync="dialogFormVisible"  >
        <el-form :model="form">
          <el-form-item label="姓名" :label-width="formLabelWidth">
            <el-input v-model="form.username" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="英文名" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="密码" :label-width="formLabelWidth">
            <el-input v-model="form.password" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="住址" :label-width="formLabelWidth">
            <el-input v-model="form.address" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="基础额度" :label-width="formLabelWidth">
            <el-input v-model="form.baseLimit" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addOperator">确 定</el-button>
        </div>
      </el-dialog>
      <el-table :data="tableData" :header-cell-style="{lineHeight:'60px'}"border style="width: 100%">
        <el-table-column prop="id" label="编号" ></el-table-column>
        <el-table-column prop="username" label="姓名" ></el-table-column>
        <el-table-column prop="name" label="英文名" ></el-table-column>
        <el-table-column prop="address" label="地址" ></el-table-column>
        <el-table-column prop="baseLimit" label="基础额度" ></el-table-column>
        <el-table-column fixed="right" label="操作" width="280">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" slot="reference">修改</el-button>
            <el-button slot="reference" @click="deleteById(scope.row)">删除</el-button>
            <el-button slot="reference" @click="chakan()">查看</el-button>
          </template>
        </el-table-column>
      </el-table>


    </div>
</template>

<script>
  import axios from 'axios'
  export default {
    data() {
      return {
        tableData: [ ],
        dialogFormVisible: false,
        form: {
          delivery: false,
        },
        formLabelWidth: '120px'
      };
    },
    methods: {
      addOperator2:function(){
        this.dialogFormVisible = true
      },
      findAll2:function () {
        axios.post("http://localhost:9999/credit-loanapplication/selectAll",{ss:1}).then(res=>{
          console.log(res.data),
            this.gridData=res.data.message;
        })
      },
      findAll:function () {
        axios.get("http://localhost:9999/credit-operators/findAll").then(res=>{
          console.log(res.data),
          this.tableData=res.data.message;
        })
      },
      addOperator:function () {
        axios.post("http://localhost:9999/credit-operators/insertAndUpdate",this.form).then(res=>{
          if(res.data.code==1200){
            this.dialogFormVisible = false
            this.form=res.data;
            this.findAll();
          }
        })
      },
      handleClick:function(row) {
        axios.post("http://localhost:9999/credit-operators/findById",{id:row.id}).then(res=>{
          if(res.data.code==10002){
            this.form=res.data.message;
          this.dialogFormVisible = true
          }
        })
      },
      deleteById:function (row) {
        axios.post("http://localhost:9999/credit-operators/deleteById",{id:row.id}).then(res=>{
          if(res.data.code==10003) {
            //alert(res.data.message)
            this.findAll()
          }
        })
      },
      chakan:function () {
        this.$router.push("/loanapplication")
      }
    },
    mounted(){
      this.findAll();
      this.findAll2();
    }
  }
</script>
